package com.dcy.iterator;

import java.util.Iterator;
import java.util.List;

/**
 * @Author：dcy
 * @Description:
 * @Date: 2021/1/28 9:48
 */
public class OutputImpl {

    // 学院集合
    List<College> collegeList;

    public OutputImpl(List<College> collegeList) {
        this.collegeList = collegeList;
    }

    // 遍历所有学院，然后调用printDepartment 输出各个学院的系
    public void printCollege() {
        // 从collegeList 取出学院，JAVA当中的
        Iterator<College> iterator = collegeList.iterator();

        while (iterator.hasNext()) {
            College college = iterator.next();
            System.out.println("=======" + college.getName() + "=======");
            // 得到对应的迭代器
            printDepartment(college.createIterator());
        }
    }

    // 输出，学院输出系
    public void printDepartment(Iterator<Department> iterator) {
        while (iterator.hasNext()) {
            Department department = iterator.next();
            System.out.println(department.getName());
        }
    }
}
